<?php
namespace Admin\Model;

use Think\Model;

/**
 * 图片上传类
 * @package Admin\Model
 */
class UploadImageModel extends Model {
    private $_uploadObj = '';
    private $_uploadImageData = '';
    const UPLOAD = 'upload';
    public function __construct()
    {
        /*实例化thinkPHP的上传类*/
        $this->_uploadObj = new \Think\Upload();
        /*上传的路劲*/
        $this->_uploadObj->rootPath = './' . self::UPLOAD . '/';
        /*上传文件的文件名称*/
        $this->_uploadObj->subName = date('Y') . '/' . date('m') . '/' . date('d');
    }
    /*thinkphp 的upload类*/
    public function upload()
    {
        $res = $this->_uploadObj->upload();
        if($res){
            return '/' . self::UPLOAD . '/' . $res['imgFile']['savepath'] . $res['imgFile']['savename'];
        }else{
            return false;
        }
    }
    /*第三方插件的上传类*/
    public function imageUpload()
    {
        $res = $this->_uploadObj->upload();
//        print_r($res);打印图片的详细信息
        /*$res['file'] 指的是js文件中的file*/
        if($res){
            return '/' . self::UPLOAD . '/' . $res['file']['savepath']  . $res['file']['savename'];
        }else{
            return false;
        }
    }
}